/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PresentationTier.Report;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Douglas
 */
public class ShowReport extends javax.swing.JInternalFrame {

    /**
     * Creates new form ShowReport
     */
  Connection conn;
    
    public ShowReport()
    {
      super("Report Viewer", true, true, true, true);
      initComponents();
      setBounds(10, 10, 600, 500);
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    public ShowReport(String filename, HashMap param) throws Exception{
      this();
      try{
          this.conn = getConnection();
          JasperPrint print = JasperFillManager.fillReport(filename, param, conn);
          JasperViewer.viewReport(print);          
      }catch(JRException jre){
          
      }
    }
    
    public ShowReport(String filename) throws Exception{
      this(filename, null);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 394, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 274, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    private Connection getConnection() throws ClassNotFoundException, SQLException{
        String driver="com.mysql.jdbc.Driver";
        String url="jdbc:mysql://localhost:3306/sgc_teste";
        String user="root";
        String password="129023";
        Class.forName(driver);
        Connection con = DriverManager.getConnection(url, user, password);
        return con;
    }
}
